﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class Manage_Emp_Answer : AdminPageBase
{
    private string returnURL;
    protected int planfinishid = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckAdmin();
        GetUserPermisions();
        if (Request.QueryString["returnURL"]!=null)
        returnURL = Request.QueryString["returnURL"].ToString();
        GetPlanFinishId();
       
        GetAnswer();

    }
    protected void CheckAdmin()
    {
        if (AdminSessionHelper.UserDetails == null)
        {
            JsHelper.TopAlertRedirect("请先登录", "../login.aspx", this.Page);
        }


    }
    protected void GetPlanFinishId()
    {
        if (Request.QueryString["id"] != null)
        {
            planfinishid = Convert.ToInt32(Request.QueryString["id"]);

        }
    }
    protected void btnreturn_Click(object sender, EventArgs e)
    {
        Response.Redirect(returnURL);
    }
    protected void GetAnswer()
    {
        if (planfinishid!= 0)
        {
          

            DataSet ds = jtDataAccess.GetAnswer(planfinishid);
            if (CoreTools.CheckDataSet(ds))
            {
               
                GridviewControl.GridViewDataBind(this.GridView1, ds.Tables[0]);

            }
            else
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("StudyAnswerId");
                dt.Columns.Add("StudyDate");
                dt.Columns.Add("FinishDate");
                dt.Columns.Add("PlanFinishId");
                dt.Columns.Add("SN");
                dt.Columns.Add("Question");
                dt.Columns.Add("RightAnswers");
                dt.Columns.Add("EmpAnswer");
                dt.Columns.Add("Score");
                dt.Columns.Add("Actualscore");
               
                GridviewControl.GridViewDataBind(this.GridView1, dt);
                GridviewControl.ResetGridView(this.GridView1);
            }
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //首先判断是否是数据行
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当鼠标停留时更改背景色
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FCFDEE'");
            //当鼠标移开时还原背景色
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            e.Row.Cells[0].Attributes.Add("class", "text");
            Label lblstartdate = (Label)e.Row.FindControl("lblStudyDate");
            Label lblenddate = (Label)e.Row.FindControl("lblFinishDate");
            Label lbScore = (Label)e.Row.FindControl("lblScore");
            Label lblActualscore = (Label)e.Row.FindControl("lblActualscore");
            LinkButton lbtndel = (LinkButton)e.Row.FindControl("lbtndel");
            if (lblstartdate != null && lblstartdate.Text != "")
            {
                lblstartdate.Text = Convert.ToDateTime(lblstartdate.Text).ToShortDateString().Replace("1900/1/1", "");
            }
            if (lblenddate != null && lblenddate.Text != "")
            {
                lblenddate.Text = Convert.ToDateTime(lblenddate.Text).ToShortDateString().Replace("1900/1/1", "").Replace("2099/12/31", "");
            }
           
            if (lbtndel != null && lblenddate.Text == "" && delete == 1)
            {
                lbtndel.Visible = true;
            }
            else if (lbtndel != null)
                lbtndel.Visible = false;

            if (lbScore != null && lbScore.Text.Equals("0.00"))
                lbScore.Text = "0";
            if (lblActualscore != null && lblActualscore.Text.Equals("0.00"))
                lblActualscore.Text = "0";
        }
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("del"))
        {
            if (AdminSessionHelper.UserDetails != null)
            {
                int userid = Convert.ToInt32(AdminSessionHelper.UserDetails["UserId"].ToString());
                int flag = jtDataAccess.DelStudyAnswer(Convert.ToInt32(e.CommandArgument.ToString()), userid);

                switch (flag)
                {
                    
                    case 0:
                        ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("删除失败！"), false);
                        break;

                    case 1:
                        ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("删除成功！"), false);
                        GetAnswer();
                        break;

                    default:
                        break;
                }
            }
        }
    }
}